#include <reg52.h>

sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;

unsigned char LEDChar[] = {
	0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
	0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};

char diplay_numbers[8] = { 0,0,0,0,0,0,0,0 };
void display(char diplay_numbers[]) {
	char i = 0;
	char delay = 200;
	for (i = 0;i < 8;i++,delay = 200) {
		switch(i){
			case 0: LSC=1;LSB=1;LSA=1;break;
			case 1: LSC=1;LSB=1;LSA=0;break;
			case 2: LSC=1;LSB=0;LSA=1;break;
			case 3: LSC=1;LSB=0;LSA=0;break;
			case 4: LSC=0;LSB=1;LSA=1;break;
			case 5: LSC=0;LSB=1;LSA=0;break;
			case 6: LSC=0;LSB=0;LSA=1;break;
			case 7: LSC=0;LSB=0;LSA=0;break;
			default: break;
		}
		P0 = LEDChar[diplay_numbers[i]];
		while (delay--);
		P0=0x00;
	}
}

int main() {
	char cnt = 1;
	TMOD = 0x01;
	TH0 = 0xB8;
	TL0 = 0x00;
	TR0 = 1;
	while (1) {
		if (TF0 == 1) {
			TF0 = 0;
			TH0 = 0xB8;
			TL0 = 0x00;
			cnt++;
			if (cnt >= 50) {
				for (cnt = 7;cnt >= 0; cnt--) {
					diplay_numbers[cnt] = diplay_numbers[cnt] + 1;
					if (diplay_numbers[cnt] < 10) {
						break;	
					}
					diplay_numbers[cnt] = 0;
				}
				cnt = 0;
			}
		}
		display(diplay_numbers);
	}
	return 1;
}